Skip to content

Handle unexpected HTTP 2XX responses#96

Open
edsu wants to merge 2 commits intodigital-science:masterfrom
edsu:handle-202
Open

Handle unexpected HTTP 2XX responses#96
edsu wants to merge 2 commits intodigital-science:masterfrom
edsu:handle-202

Conversation

@edsu
Copy link
Copy Markdown

@edsu edsu commented Apr 10, 2026

When HTTP 202 responses are returned from the API that can cause query() to return None, which causes problems in query_iterative() which isn't expecting a return value of None.

It seems like we would want to surface unexpected HTTP responses as an exception. This change to query() will treat any unhandled HTTP response as an exception.

Fixes #95

It also can be useful to retry requests when doing iterative queries. If the HTTP 202 responses really are transient they will get retried, like other responses that aren't explicitly handled.

When HTTP 202 responses are returned from the API that can cause query()
to return None, which causes problems in query_iterative() which doesn't
handle that situation. It seems like we would want to surface unexpected
HTTP responses as an exception. This change to query() will treat any
unhandled HTTP response as an exception.

Fixes digital-science#95

It also can be useful to retry requests when doing iterative queries. If
the HTTP 202 responses really are transient they will get retried, like
other errors.
I saw this error go by when using query_iterative():

```
TypeError: '>' not supported between instances of 'NoneType' and 'int'
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1112 in run
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1523 in _execute_task
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 417 in wrapper
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/decorator.py", line 252 in execute
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 417 in wrapper
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/python.py", line 228 in execute
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/python.py", line 251 in execute_callable
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/callback_runner.py", line 82 in run
File "/opt/airflow/rialto_airflow/dags/harvest.py", line 82 in dimensions_harvest
File "/opt/airflow/rialto_airflow/harvest/dimensions.py", line 42 in harvest
File "/opt/airflow/rialto_airflow/harvest/dimensions.py", line 108 in publications_from_orcid
File "/opt/airflow/rialto_airflow/harvest/dimensions.py", line 217 in query_with_retry
File "/home/airflow/.local/lib/python3.12/site-packages/dimcli/core/api.py", line 342 in query_iterative
File "/home/airflow/.local/lib/python3.12/site-packages/dimcli/core/api.py", line 325 in query_iterative
```

It seems like ensuring `tot` is not `None` here will help matters?
Comment thread dimcli/core/api.py

new_skip = skip+limit
if tot > 0 and new_skip > tot:
if tot is not None and tot > 0 and new_skip > tot:
Copy link
Copy Markdown
Author

@edsu edsu Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We ran into a situation where (somehow) tot = None which caused an exception here.

@edsu
Copy link
Copy Markdown
Author

edsu commented Apr 14, 2026

@lambdamusic I would be curious to hear what you make of this change. We hadn't been seeing 202 responses for over a year, but suddenly started seeing them in the last week or so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Occasional HTTP 202 responses are not handled

1 participant